package com.yuandengta.common.utils;

import java.io.*;

/**
 * 读取文本文件 {@link ReadTxtUtils}
 *
 * @author Kevin
 * @email: 178676392@qq.com
 */
public class ReadTxtUtils {

    public static String readTxtFile(InputStream inputStream) {
        String content = null;
        StringBuilder sb = new StringBuilder();
        if (inputStream != null) {
            BufferedReader reader = null;
            String tempStr = null;
            try {
                reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));
                while ((tempStr = reader.readLine()) != null) {
                    sb.append(tempStr);
                }
                content = sb.toString();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                if (reader != null) {
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }

        return content.trim();
    }
}
